import { reactive } from "../../reactive";
import { effect, depsMap } from "../../effect/effect";

const state = reactive({
  a: 123,
  b: 456,
  c: 789,
});

// 每次执行effect的函数时，就去重新收集一遍依赖，收集依赖之前，调用cleanup，清除之前的依赖
effect(() => {
  if (state.a > 100) state.b;
  else state.c;
  console.log("fn1被执行啦");
  console.log("-----------------");
});

effect(function fn2() {
  state.b;
  console.log("fn2");
  console.log("-----------------");
});

effect(function fn3() {
  state.c;
  console.log("fn3");
  console.log("-----------------");
});

console.log("完整的depsMap：", depsMap); // 此时的依赖是a1，b2，c1

state.a = 1;
console.log("完整的depsMap：", depsMap); // 此时的依赖是a1，b1，c2
